Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Crosswalk instances for: NonEmpty, Proxy, Const, Functor.Sum, These1 #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mniip
Copy link

@mniip mniip commented Feb 6, 2024

No description provided.

@mniip mniip changed the title Add Crosswalk instances for: NonEmpty, Proxy, Const, Functor.Sum, MaybeT Add Crosswalk instances for: NonEmpty, Proxy, Const, Functor.Sum, These1, MaybeT Feb 8, 2024
@mniip
Copy link
Author

mniip commented Feb 19, 2024

@phadej Thoughts?

@mniip
Copy link
Author

mniip commented Jun 25, 2024

@phadej gentle prod?

@mniip
Copy link
Author

mniip commented Sep 26, 2024

Do you disagree with some of the instances? Would it help to split this into 6 pull requests?

Fill deff fs <*> Fill defx xs
= Fill (deff defx) (alignWith (uncurry id . fromThese deff defx) fs xs)

instance Traversable t => Crosswalk (MaybeT t) where
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right (even the tests pass). MaybeT t is essentially Compose t Maybe, and I't expect the instance to be exactly that.

Copy link
Author

@mniip mniip Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we look at sequenceL @Maybe as a sort of generalization of catMaybes (that returns Nothing if input was all Nothings), then Crosswalk (Compose f g) first removes Nothings from g's, and if that removed all Nothings, it then removes the g altogether from f, using Crosswalk f.

Crosswalk (MaybeT f) doesnt do this last step, hence being traversable is sufficient.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Crosswalk (MaybeT t) behaves differently than Compose t Maybe? If it's so, I'd rather not add this instance at all.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It doesn't have to be on the MaybeT type constructor specifically (could be a newtype wrapper), but an instance that behaves like this is immensely useful, because it allows implementing sequenceL for any type that can implement catMaybes (witherable):

sequenceL @t xs = catMaybes @t . runMaybeT <$> sequenceL @(MaybeT t) (MaybeT (Just <$> xs))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you claiming that every Witherable is also Crosswalk?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's so, I'd rather not add this instance at all.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed it from this PR, maybe let's have a separate discussion about it.

@mniip mniip changed the title Add Crosswalk instances for: NonEmpty, Proxy, Const, Functor.Sum, These1, MaybeT Add Crosswalk instances for: NonEmpty, Proxy, Const, Functor.Sum, These1 Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants